<template>
	<view>
		<StatusBar />
		<view style="height: 200vh;">
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				share_id: 0,
				leader_id: 0
			}
		},
		async onLoad(e) {
			console.log('index',e)
			let location = await this.get('location/ip_info')
			if(location.code===1){
				uni.setStorageSync('location',location)
			}
			let {code:code2,configs} = await this.get('index/configs')
			if(code2===1){
				uni.setStorageSync('configs',configs)
			}
			if(e.share_id){
				uni.setStorageSync('share_id',e.share_id)
			}
			if(e.leader_id){
				uni.setStorageSync('leader_id',e.leader_id)
			}
			if(e.redirect_url){
				uni.setStorageSync('redirect_url',decodeURIComponent(e.redirect_url))
			}
			

			// #ifdef MP-WEIXIN
				let tokenCache = uni.getStorageSync('token')
				if(!tokenCache){
					uni.login({
					  provider: 'weixin',
					  success:  (loginRes)=> {
					    console.log('weixin-loginRes',loginRes);
						this.get('login/code_to_openid',{code:loginRes.code}).then(({code,msg,openid,token,user_id})=>{
							if(code==1){
								uni.setStorageSync('openid',openid)
								uni.setStorageSync('token',token)
								uni.setStorageSync('user_id',user_id)
								this.redirect('/pages/index/home')
							}else{
								this.error(msg||'微信登录失败')
							}
						})
					  }
					});
				}else{
					this.redirect('/pages/index/home')
				}
			// #endif
			// #ifdef MP-TOUTIAO
				let url = '/pages/index/home';
				if(e.leader_id)url += ('?leader_id=' + e.leader_id);
				if(e.share_id)url += ('?share_id=' + e.share_id);
				
				let tokenCache = uni.getStorageSync('token')
				if(!tokenCache){
					uni.login({
					  provider: 'toutiao',
					  success:  (loginRes)=> {
					    console.log('toutiao-loginRes',loginRes);
						this.get('login/douyin_code_to_openid', {code:loginRes.code}).then(({code,openid,token,user_id})=>{
							if(code==1){
								uni.setStorageSync('openid',openid)
								uni.setStorageSync('token',token)
								uni.setStorageSync('user_id',user_id)
								this.redirect(url)
							}else{
								this.error(msg||'抖音登录失败')
							}
						})
					  }
					});
				}else{
					this.redirect(url)
				}
			// #endif
			// #ifdef APP-PLUS || H5
				this.redirect('/pages/common/tel_login')
			// #endif
		},
		methods: {
			
		},
		onPageScroll(e){
			console.log('onPageScroll',e)
		},
		onReachBottom(){
			console.log('onReachBottom')
		},
		onPullDownRefresh(){
			console.log('onPullDownRefresh')
			setTimeout(()=>{
				uni.stopPullDownRefresh()
			},2000)
		},
	}
</script>

<style lang="less" scoped>
</style>
